package com.patchmanage.back.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.patchmanage.back.entity.DepartmentGroup;
import com.patchmanage.back.mapper.DepartmentGroupMapper;
import com.patchmanage.back.service.IDepartmentGroupService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author huizhao
 * @since 2021-03-27
 */
@Service
public class DepartmentGroupServiceImpl extends ServiceImpl<DepartmentGroupMapper, DepartmentGroup> implements IDepartmentGroupService {


    /**
     * 递归获取组织及组织的子节点
     * @param id
     * @return   14
     */
    public Set<Integer> recursiveGetIds(Integer id,Set<Integer> returnIds){

        returnIds.add(id);

        QueryWrapper<DepartmentGroup> qw = new QueryWrapper();
        qw.eq("p_id",id);
        List<DepartmentGroup> departmentGroupList = list(qw);

        for(DepartmentGroup departmentGroup : departmentGroupList){
            returnIds.add(departmentGroup.getId());

            recursiveGetIds(departmentGroup.getId(),returnIds);
        }


        return returnIds;
    }
}
